/**
 * 依赖包：jquery.min.js、etb-collection.js
 */
ListForm = function(formId) {
	if(!formId) {
		alert("没有指定表单ID!");
	}
	this.formEntity = $(formId);
};
ListForm.prototype.getData = function() {
	var map = new Map();
	var errorMsg;
	$(this.formEntity).find(".textbox-value").each(function(){
		if(!this.name || this.name == "") {
			errorMsg = "查询条件缺少name属性值"
		} else if(map.contains(this.name)){
			errorMsg = "查询条件出现多次：" + this.name;
		} else {// if(this.name && this.name.indexOf("criteria") == 0 && this.name.indexOf("[") > 0 && this.name.indexOf("]") > 0 && (this.name.indexOf("order") > 0 || this.name.indexOf("expr") > 0)) {
			map.put(this.name, this.value);
		}
	});
	if(errorMsg) {
		alert(errorMsg);
		return null;
	}
	return map.toJson();
};

showErrorMsg = function(e) {
	alert("服务器端异常！");
};

dateformatter = function(date) {
	if(date) {
		var y = date.year + 1900;
		var m = date.month + 1 + "";
		var d = date.date + "";
		if(m.length == 1) {
			m = "0" + m;
		}
		if(d.length == 1) {
			d = "0" + d;
		}
		return y+"-"+m+"-"+d;
	}
};
timeformatter = function(date) {
	if(date) {
		var y = date.year + 1900;
		var m = date.month + 1 + "";
		var d = date.date + "";
		var h = date.hours + "";
		var mi = date.minutes + "";
		var s = date.seconds + "";
		if(m.length == 1) {
			m = "0" + m;
		}
		if(d.length == 1) {
			d = "0" + d;
		}
		if(h.length == 1) {
			h = "0" + h;
		}
		if(mi.length == 1) {
			mi = "0" + mi;
		}
		if(s.length == 1) {
			s = "0" + s;
		}
		return y+"-"+m+"-"+d + " " + h + ":" + mi + ":" + s;
	}
};

ajax = function(param) {
	if(!param.type) param.type = "post";
	if(!param.async) param.async = true;
	var token = param.token;
	if(token) {
		var map;
		if(param.data) {
			map = new Map(param.data);
		} else {
			map = new Map();
		}
		map.put($("input[value='"+token+"']").attr("name"), token);
		map.put(token, $("input[name='"+token+"']").val());
		param.data = map.toJson();
	}
	jQuery.ajax({
        type: param.type,
        url: param.url,  
        data: param.data,
        traditional:true,//阻止深度序列化
        async: param.async,
        success: function(data) {
        	if(param.success) {
        		param.success(data);
        	}
    	},
    	error: function(data) {
    		alert("服务器端异常！");
    	}
	});
};
EtbUi = function() {};
EtbUi.prototype.show = function(data) {
	return new Map(data).show();
};
var eui = new EtbUi();
eui.ajax = ajax;
